package unit8;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Ex8_5_Example8_5 {
    static public void writeFile() throws IOException {
        OutputStream output = null;
        try {
            File file = new File("C:\\stu\\poem.txt");
            output = new FileOutputStream(file);
            String str = "大江东去,\n浪淘尽,\n千古风流人物。";
            byte[] buff = str.getBytes();// 将字符串转换为字节数组
            output.write(buff);
            System.out.println("写入成功");
        }
        finally {
            if (output != null) {
                // 关闭流释放底层资源
                output.close();
            }

        }
    }

    public static void main(String[] args) throws IOException {
        writeFile();
    }

}
